<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    var flag = false;
    var iframe = document.createElement('iframe');
    var getDatas = function () {
      if (flag) {
        //读取数据
        var data = iframe.contentWindow.name;
        console.log(JSON.parse(data));
        //{name: 'kevin', age: 28}
      } else {
        flag = true;
        //确保拿到数据再跳转
        setTimeout(function () {
          iframe.contentWindow.location = 'proxy.html';
        }, 500);
      }
    };

    //引入服务器的数据页面
    iframe.src = 'https://study.dt-code.fun/iframe/data.html';

    //兼容性
    if (iframe.attachEvent) {
      iframe.attachEvent('onload', getDatas);
    } else {
      iframe.onload = getDatas;
    }

    document.body.appendChild(iframe);
  </script>
</html>
